<form class="am-form" id="batchEditForm">
    <table class="am-table am-table-bordered am-table-radius am-table-hover">
        <tr>
            <th style="width:8%">升级包</th>
            <th style="width:8%">模块</th>
            <th>描述</th>
            <th style="width:12%">特殊说明</th>
            <th style="width:8%">责任人</th>
            <th style="width:8%">是否重启</th>
            <th style="width:8%">是否清除weblogic缓存</th>
            <th style="width:8%">是否先删除服务器文件</th>
        </tr>
        <tr>
            <th></th>
            <th>
                <input type="text" id="module_batch" maxlength="100" placeholder="批量填写模块名称">
            </th>
            <th>
                <input type="text" id="description_batch" maxlength="400" placeholder="批量填写升级内容描述">
            </th>
            <th>
                <input type="text" id="special_remark_batch" maxlength="400" placeholder="批量填写特殊说明">
            </th>
            <th>
                <select id="leader_userid">
                    <option value="">...</option>
                    <%for(var i=0; i<developers.length; i++){%>
                    <option value="<%=developers[i].id%>"><%=developers[i].name%></option>
                    <%}%>
                </select>
            </th>
            <th>
                <select id="is_need_reboot_batch">
                    <option value="">...</option>
                    <option value="1">重启</option>
                    <option value="0">无需重启</option>
                </select>
            </th>
            <th>
                <select id="is_need_clearcache_batch">
                    <option value="">...</option>
                    <option value="1">清除</option>
                    <option value="0">无需清除</option>
                </select>
            </th>
            <th>
                <select id="is_need_delfile_batch">
                    <option value="">...</option>
                    <option value="1">删除</option>
                    <option value="0">无需删除</option>
                </select>
            </th>
        </tr>
        <% for(var i=0; i<packages.length; i++) {%>
            <tr>
                <td>
                    <%=packages[i].name %>
                </td>
                <td>
                    <input type="text" role="module" role-module="<%=packages[i].id%>" value="<%=packages[i].module%>" maxlength="400" placeholder="模块名称">
                </td>
                <td>
                    <input type="text" role="description" role-description="<%=packages[i].id%>" value="<%=packages[i].description%>" maxlength="400" placeholder="升级内容描述">
                </td>
                <td>
                    <input type="text" role="special_remark" role-special_remark="<%=packages[i].id%>" value="<%=packages[i].special_remark%>" maxlength="400" placeholder="特殊说明">
                </td>
                <td>
                    <select role="leader_userid" role-leader_userid="<%=packages[i].id%>">
                        <option value="">...</option>
                        <%for(var j=0; j<developers.length; j++){%>
                        <option value="<%=developers[j].id%>" <%if(packages[i].leader_userid !== undefined && packages[i].leader_userid===developers[j].id){%>selected=selected<%}%>><%=developers[j].name%></option>
                        <%}%>
                    </select>
                </td>
                <td>
                    <select role="is_need_reboot" role-is_need_reboot="<%=packages[i].id%>">
                        <option value="">...</option>
                        <option value="1" <%if(packages[i].is_need_reboot !== undefined && packages[i].is_need_reboot===1){%>selected=selected<%}%>>重启</option>
                        <option value="0" <%if(packages[i].is_need_reboot !== undefined && packages[i].is_need_reboot===0){%>selected=selected<%}%>>无需重启</option>
                    </select>
                </td>
                <td>
                    <select role="is_need_clearcache" role-is_need_clearcache="<%=packages[i].id%>">
                        <option value="">...</option>
                        <option value="1" <%if(packages[i].is_need_clearcache !== undefined && packages[i].is_need_clearcache===1){%>selected=selected<%}%>>清除</option>
                        <option value="0" <%if(packages[i].is_need_clearcache !== undefined && packages[i].is_need_clearcache===0){%>selected=selected<%}%>>无需清除</option>
                    </select>
                </td>
                <td>
                    <select role="is_need_delfile" role-is_need_delfile="<%=packages[i].id%>">
                        <option value="">...</option>
                        <option value="1" <%if(packages[i].is_need_delfile !== undefined && packages[i].is_need_delfile===1){%>selected=selected<%}%>>删除</option>
                        <option value="0" <%if(packages[i].is_need_delfile !== undefined && packages[i].is_need_delfile===0){%>selected=selected<%}%>>无需删除</option>
                    </select>
                </td>
            </tr>
            <%}%>
    </table>
    <div style="text-align: center;">
        <button type="button" id="batchEditForm-save" class="am-btn am-btn-success am-radius">保存</button>
        <button type="button" id="batchEditForm-close" class="am-btn am-btn-default am-radius">关闭</button>
    </div>
</form>
<script type="text/javascript">
$(function() {
    $('#module_batch').keyup(function() {
        $('#batchEditForm [role="module"]').val($(this).val());
    });
    $('#description_batch').keyup(function() {
        $('#batchEditForm [role="description"]').val($(this).val());
    });
    $('#special_remark_batch').keyup(function() {
        $('#batchEditForm [role="special_remark"]').val($(this).val());
    });
    $('#leader_userid').change(function() {
        $('#batchEditForm [role="leader_userid"]').val($(this).val());
    });
    $('#is_need_reboot_batch').change(function() {
        $('#batchEditForm [role="is_need_reboot"]').val($(this).val());
    });
    $('#is_need_delfile_batch').change(function() {
        $('#batchEditForm [role="is_need_delfile"]').val($(this).val());
    });
    $('#is_need_clearcache_batch').change(function() {
        $('#batchEditForm [role="is_need_clearcache"]').val($(this).val());
    });

    $('#batchEditForm-save').click(function() {
        var packages = [];

        <% for(var i=0; i<packages.length; i++) {%>
        packages.push({
            id: '<%=packages[i].id%>',
            description: $('[role-description="<%=packages[i].id%>"]').val() || '',
            special_remark: $('[role-special_remark="<%=packages[i].id%>"]').val() || '',
            module: $('[role-module="<%=packages[i].id%>"]').val() || '',
            is_need_reboot: $('[role-is_need_reboot="<%=packages[i].id%>"]').val() || '',
            is_need_clearcache: $('[role-is_need_clearcache="<%=packages[i].id%>"]').val() || '',
            is_need_delfile: $('[role-is_need_delfile="<%=packages[i].id%>"]').val() || '',
            leader_userid: $('[role-leader_userid="<%=packages[i].id%>"]').val() || ''
        });
        <%}%>

        $.ajax({
            url: '/simpleUpgradePackage/doBatchUpPackage',
            dataType: "json",
            type: "post",
            data: 'packagesJson=' + JSON.stringify(packages),
            success: function(data) {
                zeroModal.closeAll();
                if (data.success) {
                    $.toast({ text: '批量修改成功！', showHideTransition: 'slide', icon: 'success', position: 'top-center' });
                } else {
                    $.toast({ text: '批量修改失败！', showHideTransition: 'slide', icon: 'error', position: 'top-center' });
                }
            }
        });
    });

    $('#batchEditForm-close').click(function() {
        zeroModal.closeAll();
    });
});
</script>